#include <vector>
#include <iostream>
#include <sstream>
#include <queue>
using namespace std;
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    vector<int> numsP, numsQ;
    // 比较遍历结果，先比较size，再逐个字符比较
    bool isSameTree(TreeNode* p, TreeNode* q) {
        if ( p == nullptr && q == nullptr) return true;
        if ( p == nullptr || q == nullptr) return false;
        numsP = inorderTraverse(p);
        numsQ = inorderTraverse1(q);
        if (numsP.size() != numsQ.size()) return false;

        int sz = numsP.size();
        for (int i = 0; i < sz; i++){
            if (numsP[i] != numsQ[i]) return false;
        }
        return true;
    }

    // 中序遍历 p
    vector<int> inorderTraverse(TreeNode* root){
        if (root == nullptr) return numsP;

        inorderTraverse(root->left);
        numsP.push_back(root->val);
        inorderTraverse(root->right);
        return numsP;
    }
    // 中序遍历q
    vector<int> inorderTraverse1(TreeNode* root){
        if (root == nullptr) return numsQ;

        inorderTraverse1(root->left);
        numsQ.push_back(root->val);
        inorderTraverse1(root->right);
        return numsQ;
    }
    void trimLeftTrailingSpaces(string &input) {
    input.erase(input.begin(), find_if(input.begin(), input.end(), [](int ch) {
        return !isspace(ch);
    }));
}

    void trimRightTrailingSpaces(string &input) {
        input.erase(find_if(input.rbegin(), input.rend(), [](int ch) {
            return !isspace(ch);
        }).base(), input.end());
    }
    // 把输入转成二叉树, e.g [1, null, 1]
    TreeNode* stringToTreeNode(string input) {
        trimLeftTrailingSpaces(input);
        trimRightTrailingSpaces(input);
        input = input.substr(1, input.length() - 2);
        if (!input.size()) {
            return nullptr;
        }

        string item;
        stringstream ss;
        ss.str(input);

        getline(ss, item, ',');
        TreeNode* root = new TreeNode(stoi(item));
        queue<TreeNode*> nodeQueue;
        nodeQueue.push(root);

        while (true) {
            TreeNode* node = nodeQueue.front();
            nodeQueue.pop();

            if (!getline(ss, item, ',')) {
                break;
            }

            trimLeftTrailingSpaces(item);
            if (item != "null") {
                int leftNumber = stoi(item);
                node->left = new TreeNode(leftNumber);
                nodeQueue.push(node->left);
            }

            if (!getline(ss, item, ',')) {
                break;
            }

            trimLeftTrailingSpaces(item);
            if (item != "null") {
                int rightNumber = stoi(item);
                node->right = new TreeNode(rightNumber);
                nodeQueue.push(node->right);
            }
        }
        return root;
    }
};

int main(){
    // test data: [1,1], [1, null,1] 不能通过
    string line;
    while(getline(cin, line)){

        Solution slu;
        TreeNode* p = slu.stringToTreeNode(line);
        getline(cin, line);
        TreeNode* q = slu.stringToTreeNode(line);
        bool ret = slu.isSameTree(p, q);
        cout<<"same test result: "<<ret<<endl;
    }
    return 0;
}